package com.example.orderserver.controller;

import com.example.orderserver.params.OrderParams;
import com.example.orderserver.params.PageOrderParams;
import com.example.orderserver.service.OrderService;
import com.example.orderserver.vo.OrderVO;
import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.vo.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/order-server")
@Api(tags = "订单接口")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "获取分页订单")
    @PostMapping(value = "/page")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<OrderVO>> pageOrder(@RequestBody PageOrderParams pageOrderParams) {
        return new Result(orderService.pageOrder(pageOrderParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取订单")
    @GetMapping(value = "/get")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<OrderVO> getGoods(@RequestParam String id) {
        return new Result(orderService.getOrder(id), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "删除订单")
    @DeleteMapping(value = "/delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteOrder(@RequestParam String id) {
        orderService.deleteOrder(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "修改订单")
    @PutMapping(value = "/update")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateOrder(@RequestBody OrderParams orderParams) {
        orderService.updateOrder(orderParams);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "新增订单")
    @PostMapping(value = "/insert")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertOrder(@RequestBody OrderParams orderParams) {
        return orderService.insertOrder(orderParams);
    }
}
